package com.bjfu.demo.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.util.CollectionUtils;

/**
 * Created on 2021-04-30
 */
public class MaxUtils {


    public static Double getMaxFromDouble(List<Double> values) {
        if (CollectionUtils.isEmpty(values)) {
            return 0D;
        }

        Double res = 0D;

        for (Double value : values) {
            if (res < value) {
                res = value;
            }
        }

        return res;

    }

    public static Double getMaxFromString(List<String> values) {
        if (CollectionUtils.isEmpty(values)) {
            return 0D;
        }

        values = values.parallelStream().filter(x -> (null != x) && (!x.contains("-"))).collect(Collectors.toList());


        List<Double> valuess = new ArrayList<>();


        for (String value : values) {

            try {
                double v = Double.parseDouble(value);
                valuess.add(v);
            } catch (Exception e) {
                e.printStackTrace();
            }

        }

        return getMaxFromDouble(valuess);

    }
}
